package com.app.controller;


import com.app.common.Result;
import com.app.model.GroupBuyingCategory;
import com.app.service.IGroupBuyingCategoryService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 团购分类表 前端控制器
 * </p>
 *
 * @author shaokuiling
 * @since 2024-09-24
 */
@RestController
@RequestMapping("/groupBuyingCategory")
public class GroupBuyingCategoryController {

    @Autowired
    private IGroupBuyingCategoryService groupBuyingCategoryService;

    /**
     * 管理后台————团购分类新增
     * @param groupBuyingCategory
     * @return
     */
    @PostMapping("/admin/addAndUpdate")
    public Result addAndUpdate(@RequestBody GroupBuyingCategory groupBuyingCategory) {
        return groupBuyingCategoryService.addAndUpdate(groupBuyingCategory);
    }


    @GetMapping("/applet/queryGroupBuyingCategory")
    public Result appletQueryGroupBuyingCategory(Integer businessId){
        QueryWrapper<GroupBuyingCategory> groupBuyingCategoryQueryWrapper = new QueryWrapper<>();
        groupBuyingCategoryQueryWrapper.eq("business_id", businessId);
        groupBuyingCategoryQueryWrapper.eq("status", 1);
        return Result.success(groupBuyingCategoryService.list(groupBuyingCategoryQueryWrapper));
    }

    /**
     * 管理后台————根据商家Id查询分类列表
     * @param businessId
     * @return
     */
    @GetMapping("/getListByActivityId")
    public Result getListByActivityId(Integer businessId, @RequestParam(required = false,defaultValue = "1") Integer page,@RequestParam(required = false,defaultValue = "10") Integer limit) {
        return groupBuyingCategoryService.getListByActivityId(businessId,page,limit);
    }

    /**
     * 管理后台————删除团购
     * type 1子表仍有关联数据不予删除 2强制删除关联的子表数据
     */
    @GetMapping("/delete")
    public Result deleteIdWithType(Integer cid,Integer type) {
        return groupBuyingCategoryService.deleteIdWithType(cid,type);
    }

    /**
     * 管理后台————根据分类Id查分类的详情
     * @param cid
     * @return
     */
    @GetMapping("/getCategoryDetail")
    public Result getCategoryDetail(Integer cid) {
        return groupBuyingCategoryService.getCategoryDetail(cid);
    }

}

